<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">kafka地址</label>
        <div class="layui-input-block">
            <input type="text" id="topic" name="topic" lay-verify="required" lay-reqtext="全局变量不能为空" placeholder="请输入全局变量" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/common.js" charset="utf-8"></script>
<script src="../../js/base.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer;
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            save(JSON.stringify(data.field));
            return false;
        });
        $(function () {
        })
    });
    var save = function (data) {
        $.ajax({
            type:'POST',	//请求的类型,GET、POST等
            url:window.reqPath("topic/save"),	//向服务器请求的地址。
            contentType:'application/json',	//向服务器发送内容的类型，默认值是：application/x-www-form-urlencoded
            dataType:'JSON',	//预期服务器响应类型
            async:true,	//默认值是true,表示请求是异步的，false是同步请求，同步请求会阻碍浏览器的其他操作（不建议使用）
            data:data,
            success:function(result,status,XMLHttpRequest){		//请求成功是执行的函数,result：服务器返回的数据，    status：服务器返回的状态，
                layer.msg(result.msg);
            },
            error:function(xhr,status,error){	//请求失败是执行的函数

            },
            complete:function(xhr,status){
                //不管请求失败还是请求成功，都执行的函数
            }
        })
    }
</script>
</body>
</html>